using System;
using System.IO;

namespace lucere.test.util
{
	public class TestUtil
	{
		public static DirectoryInfo GetTempDir(string description)
		{
			var tempDir = Environment.GetEnvironmentVariable("TMP")??"";
			if (!Directory.Exists(tempDir))
				throw new Exception("TMP dir undefined, cannot run test");
			return new DirectoryInfo(Path.Combine(tempDir, description + "." + new Random().Next()));
		}

		public static void RemoveDir(DirectoryInfo dir)
		{
			if (dir.Exists)
			{
				var files = dir.GetFiles();
				foreach (var fileInfo in files)
				{
					fileInfo.Delete();
				}
				dir.Delete();
			}
		}
	}
}